﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script>
        /*
           第一种：
               字符串转数组，反转数组，数组转字符串。
               
               split("")：根据空字符串拆分数组
               reverse()：数组反转元素位置
               join("")：数组转回字符串,且不带分隔符
       */
        let str = '01234';
        let arr = str.split("");
        arr = arr.reverse();
        str = arr.join("");
        console.log(str);

        // 倒着遍历字符串，并定义新的空字符串
        let result = "这瓜保熟吗?";
        let newStr = "";
        for (let i = 0; i < result.length; i++) {
            let temp = result[result.length - 1 - i];
            console.log(temp);
            newStr = newStr + temp;
        }
        console.log(newStr);
    </script>
</body>
</html>